/* Changes in rent 1999-2007 at the regional level from CLAMEUR */
cd "C:\Users\Public\Documents\ImmPanelRevis19\ImmPanelRevis19\Donnees\pit\"
use "C:\Users\Public\Documents\ImmPanelRevis19\ImmPanelRevis19\Donnees\Loyer\reg_rent.dta", clear
egen time=group(year)
egen ireg=group(reg)
xtset ireg time
gen drent=rent/L.rent
keep if year==2007
keep reg drent
save reg_drent.dta, replace

use "C:\Users\Public\Documents\ImmPanelRevis19\ImmPanelRevis19\Donnees\pit\instru2017R21.dta", clear
keep if an==2007
keep ze zepop
save temp.dta, replace

/* ICP Adjusted 2007 */
use "C:\Users\Public\Documents\ImmPanelRevis19\ImmPanelRevis19\Donnees\Loyer\cloyer2.dta", clear
rename aze ze
joinby ze using temp.dta, unm(m)
tab _merge
drop _merge
egen totpop=sum( zepop)
gen shpop=zepop/totpop
egen lmoy=wtmean(cloyer2) , weight(shpop)
/* weighted average index of housing cost = 100 in 2008 */
gen iloy= cloyer2/ lmoy*100
/* local cost index : share of housing => 6% 20% or 30% */
gen ipcl6=100*0.94+iloy*(1-0.94)
gen ipcl20=100*0.80+iloy*(1-0.80)
gen ipcl30=100*0.70+iloy*(1-0.70)
gen an=2007
keep ze iloy ipcl6 ipcl20 ipcl30 an zepop
rename ze aze
save ipca07.dta, replace

/* IPC 99 */
use "C:\Users\Public\Documents\ImmPanelRevis19\ImmPanelRevis19\Donnees\Loyer\cloyer2.dta", clear
gen reg=substr(aze,1,2)
destring reg, replace
joinby reg using reg_drent.dta,  unm(m)
tab _merge
drop _merge
replace drent=1.25 if missing(drent)

rename aze ze
joinby ze using temp.dta, unm(m)
tab _merge
drop _merge
egen totpop=sum( zepop)
gen shpop=zepop/totpop
/*replace cloyer2=cloyer2/drent*/
replace cloyer2=cloyer2/drent
egen lmoy=wtmean(cloyer2) , weight(shpop)
gen iloy= cloyer2/ lmoy*100
/* adjust rents to the 1999 level using regional variations */
gen ipcl6=100*0.94+iloy*(1-0.94)
gen ipcl20=100*0.80+iloy*(1-0.80)
gen ipcl30=100*0.70+iloy*(1-0.70)
gen an=1999
keep ze iloy ipcl6 ipcl20 ipcl30 an zepop
rename ze aze
save ipca99.dta, replace
append using ipca07.dta
save "C:\Users\Public\Documents\ImmPanelRevis19\ImmPanelRevis19\Donnees\Loyer\ipc_Local.dta", replace
rm reg_drent.dta
rm ipca99.dta
rm ipca07.dta
